"""
@name : 2021-05-29 流程控制作业
@author : shiyaling
@projectname : xsfh
"""
#####作业1：猜数字
import random
num1 = random.randint(0,10)
for i in range(3):
    i += 1
    num2 = input("请输入一个数字：")
    if num2.isdigit() == 1:
        if int(num1) == int(num2):
            print(f"恭喜你猜对了，你一共猜了{i}次")
        elif int(num1) > int(num2):
            print("你猜错了,你猜的数字小了")
        else:
            print("你猜错了，你猜的数字大了")
    else:
        print("输入错误！")

########作业2，计算复利
amount = int(input("请输入你要存入的金额:"))
target_amount = int(input("请输入您的目标金额:"))
for i in range(100):
    i += 1
    #计算利息
    interest = amount * 0.05 * 1
    print(f"第{i}年：本金为{amount}+利息为{interest}")
    amount = amount + interest
    if amount >= target_amount:
        break
    else:
        continue
print(f"需要{i}年，才能达到目标金额")

######作业3：空气质量查询
pm = input("请输入pm2.5的值:")
while pm != "Q":
    pm = int(pm)
    if pm <= 50:
        print("空气质量为优")
    elif 51 < pm <= 100:
        print("空气质量为良")
    elif 101 < pm <= 150:
        print("空气质量为轻度污染")
    elif 151 < pm <= 200:
        print("空气质量为中度污染")
    elif 201 < pm <= 300:
        print("空气质量为重度污染")
    else:
        print("空气质量为严重污染")
    pm = input("请输入pm2.5的值:")

#######作业四：猜大小游戏
import random
total= 0
win = 0
str1 = input("请输入您的猜测：")
gold_bean = 100
while str1 != "exit":
    num1 = random.randint(1,6)
    num2 = random.randint(1,6)
    num3 = random.randint(1,6)
    num = num1 + num2 + num3
    if num <=10:
        str2 = "小"
    else:
        str2 = "大"
    if str1 == str2:
        print("猜测正确")
        win += 1
        gold_bean += 100
    else:
        print("猜测错误")
        gold_bean -= 100
    total += 1
    if gold_bean < 100:
        print("您的金豆不足100！")
        break;
    str1 = input("请输入您的猜测：")
win_pro = win / total
print(f"胜率为{win_pro*100}%")




